<template>
  <div>
    <span>{{ serverResponse }} </span>
    <button @click="getData">GET DATA</button>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "my-first-vue",
  data: function() {
    return {
      serverResponse: "resp"
    };
  },
  methods: {
    getData() {
      var that = this;
      const path = "http://127.0.0.1:5000/getMsg";
      axios
        .get(path)
        .then(function(response) {
          // 这里服务器返回的 response 为一个 json object，可通过如下方法需要转成 json 字符串
          // 可以直接通过 response.data 取key-value
		  
          var msg = response.data.msg;
          that.serverResponse = msg;

          alert(
            "Success " + response.status + ", " + response.data + ", " + msg
          );
        })
        .catch(function(error) {
          alert("Error " + error);
        });
    }
  }
};
</script>